﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.IssuerInformation
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using Microsoft.InfoCards.Diagnostics;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;

namespace Microsoft.InfoCards
{
  internal class IssuerInformation
  {
    private List<IssuerInformationEntry> m_informationEntries;

    public IssuerInformation()
    {
      this.m_informationEntries = new List<IssuerInformationEntry>();
    }

    public void Serialize(Stream stream)
    {
      BinaryWriter writer = new BinaryWriter(stream, Encoding.Unicode);
      writer.Write(this.m_informationEntries.Count);
      if (this.m_informationEntries.Count <= 0)
        return;
      foreach (IssuerInformationEntry informationEntry in this.m_informationEntries)
      {
        Utility.SerializeString(writer, informationEntry.Name);
        Utility.SerializeString(writer, informationEntry.Value);
      }
    }

    public void ReadIssuerInformation(XmlReader reader)
    {
      if (!reader.IsStartElement(nameof (IssuerInformation), "http://schemas.xmlsoap.org/ws/2007/01/identity"))
        throw InfoCardTrace.ThrowHelperError((Exception) new XmlException(SR.GetString("UnexpectedElement")));
      while (reader.Read())
      {
        if ("IssuerInformationEntry" == reader.LocalName && "http://schemas.xmlsoap.org/ws/2007/01/identity" == reader.NamespaceURI)
          this.ReadIssuerInformationEntry(reader);
        if (nameof (IssuerInformation) == reader.LocalName && "http://schemas.xmlsoap.org/ws/2007/01/identity" == reader.NamespaceURI && XmlNodeType.EndElement == reader.NodeType)
          break;
      }
    }

    public void ReadIssuerInformationEntry(XmlReader reader)
    {
      if (!reader.IsStartElement("IssuerInformationEntry", "http://schemas.xmlsoap.org/ws/2007/01/identity"))
        throw InfoCardTrace.ThrowHelperError((Exception) new XmlException(SR.GetString("UnexpectedElement")));
      string name = string.Empty;
      string str = string.Empty;
      while (reader.Read())
      {
        if ("IssuerInformationEntry" == reader.LocalName && "http://schemas.xmlsoap.org/ws/2007/01/identity" == reader.NamespaceURI && XmlNodeType.EndElement == reader.NodeType)
        {
          this.m_informationEntries.Add(new IssuerInformationEntry(name, str));
          break;
        }
        if ("EntryName" == reader.LocalName && "http://schemas.xmlsoap.org/ws/2007/01/identity" == reader.NamespaceURI)
        {
          name = reader.ReadString();
          if (string.IsNullOrEmpty(name))
            throw InfoCardTrace.ThrowHelperError((Exception) new InvalidCardException());
        }
        if ("EntryValue" == reader.LocalName && "http://schemas.xmlsoap.org/ws/2007/01/identity" == reader.NamespaceURI)
          str = reader.ReadString();
      }
    }
  }
}
